package org.example.system.controller;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.example.system.entity.LoginLog;
import org.example.system.service.LoginLogService;
import org.example.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 登录日志控制层
 */
@RestController
@Slf4j
@RequestMapping("/admin/loginlog")
public class LoginLogController {
    @Autowired
    private LoginLogService loginLogService;

    /**
     * 按条件分页查询
     * @param loginLog
     * @return
     */
    @GetMapping("/list")
    public R list(LoginLog loginLog){
        IPage<LoginLog> page = loginLogService.selectPage(loginLog);
        log.info("------------ LoginLogController | list | selectPage | return : {} ", JSON.toJSONString(page));
        return R.ok(page);
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @DeleteMapping( "/{ids}")
    public R delete(@PathVariable("ids") Long[] ids){
        log.info("--------- LoginLogController | delete | input : {}", JSON.toJSON(ids));
        int row = loginLogService.deleteBatch(ids);
        if(row <= 0){
            return  R.fail("删除失败");
        }
        return R.ok("删除成功");
    }
}
